package com.example.perplonews.a_a_mvp.presenter.presenters

import BasePresenter
import IPresenter
import Tokencontract
import com.example.perplonews.a_b_entity.BaseEntity
import com.example.perplonews.a_b_entity.ToKenEntity
import com.example.perplonews.a_b_utils.LjlUtils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers


class TokenPresenter(myModel: Tokencontract.Token_MyModel, myView: Tokencontract.Token_MyView) : BasePresenter<Tokencontract.Token_MyModel, Tokencontract.Token_MyView>(myModel,myView),
    IPresenter {
    fun requestToken(){
        var map:HashMap<String,Any>?= HashMap()

        map?.put("imie",""+System.currentTimeMillis())
        mymodel.requestToken(map!!).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(this)

    }

    override fun onNext(t: BaseEntity) {
        var toKenEntity = t as ToKenEntity
        if (toKenEntity.status.equals("200")){
            //存入sp
                LjlUtils.Ljl_Loge(
                    "已保存"+toKenEntity.getValues()?.token

                )
            LjlUtils.setSpData("token",""+toKenEntity.getValues()?.token)

            myview.refresh()

        }



    }
}